package com.neuedu.hisadmin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.neuedu.hisadmin.entity.Register;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface RegisterMapper extends BaseMapper<Register> {

    // 根据关键字查询可退号的挂号记录（状态为已挂号等）
    @Select("SELECT * FROM register " +
            "WHERE (RealName LIKE CONCAT('%', #{keyword}, '%') " +
            "OR IDnumber LIKE CONCAT('%', #{keyword}, '%') " +
            "OR Phone LIKE CONCAT('%', #{keyword}, '%')) " +
            "AND VisitState = '已挂号'")
    List<Register> selectRefundableRegisters(@Param("keyword") String keyword);

    // 更新挂号状态为已退号，释放号源
    @Update("UPDATE register SET VisitState = '已退号', IsBook = 0 WHERE ID = #{registerId}")
    int updateRegisterState(@Param("registerId") Integer registerId);
}